/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.agilelang.object;

import org.agilelang.object.ObjectClass;
import org.agilelang.object.ObjectProject;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

/**
 *
 * @author Roderick
 */
public class Read {

    public ObjectProject process(String path_xml) {
       

        File file = new File(path_xml);
        if (!file.exists()) {
            System.err.println("Fichero XML no existe");
            //return null;
        }
        //leer xml
        InputStream is = null;
        Reader reader = null;
        try {
            is = new FileInputStream(path_xml);
            reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            System.out.println("Reding xml...");
        } catch (FileNotFoundException | UnsupportedEncodingException ex) {
            System.err.println("Error al leer fichero XML : " + ex);
        }
        //Poblar objecto Project        
        JAXBContext jc;
        ObjectProject class_obj = null;
        try {
            jc = JAXBContext.newInstance(ObjectProject.class);
            Unmarshaller u = jc.createUnmarshaller();
            class_obj = (ObjectProject) u.unmarshal(reader);
            System.out.println("Built project...");
        } catch (JAXBException ex) {
            System.err.println("Error al poblar objeto Project : " + ex.toString());
        }

        return class_obj;
    }

    public static void main(String[] args) {
        ObjectProject agileproject = null;
        String path_xml = "C:\\Users\\Roderick\\Documents\\NetBeansProjects\\AgileLangReadJson\\Test\\syntax.xml";
        Read rd = new Read();
        agileproject = rd.process(path_xml);
        
    }
}
